home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / AppleEvents / Events / ConstAEAttribute.cp < prev    next >
Text File  |  2000-06-23  |  2KB  |  106 lines

  1. // ConstAEAttribute.cp
  2.  
  3. #ifndef ConstAEAttribute_h
  4. #include "ConstAEAttribute.h"
  5. #endif
  6. #ifndef OSError_h
  7. #include "OSError.h"
  8. #endif
  9. #ifndef Buffer_h
  10. #include "Buffer.h"
  11. #endif
  12. #ifndef AEEvent_h
  13. #include "AEEvent.h"
  14. #endif
  15.  
  16. #include <Errors.h>
  17.  
  18. bool ConstAEAttribute::Exists() const
  19.   {
  20.     Assert( !Event().IsNull() );
  21.     DescType type;
  22.     int32 size;
  23.     
  24.     OSErr error = AESizeOfAttribute( &event, key.Key(), &type, &size );
  25.     
  26.     if ( error != noErr && error != errAEDescNotFound )
  27.         throw OSError( error );
  28.     
  29.     return error == noErr;
  30.   }
  31.  
  32. uint32 ConstAEAttribute::Length() const
  33.   {
  34.     Assert( !Event().IsNull() );
  35.     DescType type;
  36.     int32 size;
  37.     ThrowOSError( AESizeOfAttribute( &event, key.Key(), &type, &size ) );
  38.     Assert( size >= 0 );
  39.     return size;
  40.   }
  41.  
  42. AEType ConstAEAttribute::Type() const
  43.   {
  44.     Assert( !Event().IsNull() );
  45.     DescType type;
  46.     int32 size;
  47.     ThrowOSError( AESizeOfAttribute( &event, key.Key(), &type, &size ) );
  48.     return AEType( type );
  49.   }
  50.  
  51. void ConstAEAttribute::operator>>( Data out ) const
  52.   {
  53.     Assert( !Event().IsNull() );
  54.     DescType type;
  55.     int32 size;
  56.     ThrowOSError( AEGetAttributePtr( &event,
  57.                                                 key.Key(),
  58.                                                 typeWildCard,
  59.                                                 &type,
  60.                                                 out.Start(),
  61.                                                 out.Length(),
  62.                                                 &size ) );
  63.   }
  64.  
  65. void ConstAEAttribute::operator>>( Buffer& out ) const
  66.   {
  67.     Assert( !Event().IsNull() );
  68.     DescType type;
  69.     int32 size;
  70.     ThrowOSError( AEGetAttributePtr( &event,
  71.                                                 key.Key(),
  72.                                                 typeWildCard,
  73.                                                 &type,
  74.                                                 out.Unused().Start(),
  75.                                                 out.Unused().Length(),
  76.                                                 &size ) );
  77.     Assert( size >= 0 );
  78.     out.AdvanceMark( size );
  79.   }
  80.  
  81. void ConstAEAttribute::Get( AEType desiredType, Data out ) const
  82.   {
  83.     Assert( !Event().IsNull() );
  84.     DescType actualType;
  85.     int32 actualSize;
  86.     ThrowOSError( AEGetAttributePtr( &event,
  87.                                                 key.Key(),
  88.                                                 desiredType.Type(),
  89.                                                 &actualType,
  90.                                                 out.Start(),
  91.                                                 out.Length(),
  92.                                                 &actualSize ) );
  93.  
  94.     Assert( actualType == desiredType.Type() );
  95.     Assert( actualSize == out.Length() );
  96.   }
  97.  
  98. AEDescriptor::AEDescriptor( const ConstAEAttribute& attribute, AEType desired )
  99.   {
  100.     Assert( !attribute.Event().IsNull() );
  101.     ThrowOSError( AEGetAttributeDesc( &attribute.Event(),
  102.                                                  attribute.Key().Key(),
  103.                                                  desired.Type(),
  104.                                                  this ) );
  105.   }
  106.